package org.example.controller;

import com.example.model.system.SysRole;
import com.example.model.vo.SysRoleQueryVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.example.common.result.Result;
import org.example.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Api(tags = "角色管理")
@RestController
@RequestMapping("admin/system/sysRole")
public class SysRoleController {

    @Autowired
    SysRoleService sysRoleService;

    @ApiOperation(value = "删除")
    @DeleteMapping("/remove/{id}")
    public boolean remove(@PathVariable Long id){
        boolean b = sysRoleService.removeById(id);
        return b;
    }

    @ApiOperation(value = "获取分页列表")
    @GetMapping("/{page}/{limit}")
    public Result index(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Long page,

            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Long limit,

            @ApiParam(name = "roleQueryVo", value = "查询对象", required = false)
            SysRoleQueryVo roleQueryVo) {
        Page<SysRole> pageParam = new Page<>(page, limit);
        IPage<SysRole> pageModel = sysRoleService.selectPage(pageParam, roleQueryVo);
        return Result.ok(pageModel);
    }
    @ApiOperation(value = "查询")
    @GetMapping("/findAll")
    public List<SysRole> findAll(){
        List<SysRole> sysRoles = sysRoleService.list();
        return sysRoles;
    }

    @ApiOperation(value = "添加")
    @PostMapping("/save")
    public boolean save(@RequestBody SysRole sysRole){
        boolean save = sysRoleService.save(sysRole);
        return save;
    }

    @ApiOperation(value = "修改")
    @PutMapping("/update")
    public boolean update(@RequestBody SysRole sysRole){
        boolean b = sysRoleService.updateById(sysRole);
        return b;
    }
}
